import request from '@/utils/request'

export function addRole(pram) {
  const data = {
    level: pram.level,
    roleName: pram.roleName,
    status: pram.status,
    rules: pram.rules.join(',')
  }
  // data.rules = pram.rules.join(',')
  return request({
    url: '/admin/system/role/save',
    method: 'POST',
    data: data
  })
}

export function delRole(pram) {
  const data = {
    id: pram.id
  }
  return request({
    url: '/admin/system/role/delete',
    method: 'GET',
    params: data
  })
}

export function getInfo(pram) {
  const data = {
    ids: pram.id
  }
  return request({
    url: '/admin/system/role/info',
    method: 'get',
    params: data
  })
}

export function getRoleList (params) {
  const data = {
    createTime: params.createTime,
    updateTime: params.updateTime,
    level: params.level,
    page: params.page,
    limit: params.limit,
    roleName: params.roleName,
    rules: params.rules,
    status: params.status
  }
  return request.post('/admin/system/role/list', data)
}


export function updateRole (params) {
  const data = {
    id: params.id,
    level: params.level,
    roleName: params.roleName,
    rules: params.rules.join(','),
    status: params.status
  }
  return request({
    url: '/admin/system/role/update',
    method: 'post',
    params: {id: params.id},
    data: data
  })
}
